{% set session = _context.app.session|default(null) %}

{% if session is not null and session.started %}
    {% set icons = {
        'success': 'tabler:circle-check',
        'error': 'tabler:exclamation-circle',
        'info': 'tabler:info-circle',
        'warning': 'tabler:alert-triangle',
    } %}

    <div class="container-xl" {{ sylius_test_html_attribute('sylius-flashes-container') }}>
        {% for type in ['success', 'error', 'info', 'warning'] %}
            {% for flash in session.flashbag.get(type) %}
                <div
                    class="mt-3 sylius alert alert-{{ type == 'error' ? 'danger' : type }} alert-dismissible"
                    role="alert"
                    {{ sylius_test_html_attribute('sylius-flash-message') }}
                    {{ sylius_test_html_attribute('sylius-flash-message-type', type) }}
                >
                    <div class="alert-icon">
                        {{ ux_icon(icons[type]) }}
                    </div>
                    <div>
                        <h4 class="alert-heading">
                            {% set header = 'sylius.ui.' ~ type %}
                            {{ header|trans }}
                        </h4>
                        <div class="alert-description">
                            {% if flash is iterable %}
                                {{ flash.message|trans(flash.parameters, 'flashes') }}
                            {% else %}
                                {{ flash|trans({}, 'flashes') }}
                            {% endif %}
                        </div>
                    </div>
                    <a class="btn-close" data-bs-dismiss="alert" aria-label="close">
                        {{ ux_icon('tabler:x') }}
                    </a>
                </div>
            {% endfor %}
        {% endfor %}
    </div>
{% endif %}
